package com.tangkun.environment.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tangkun.environment.R;
import com.tangkun.environment.entity.gongzuo.DepartmentChildReturn;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author tangkun
 * @ClassName: WuRanYuanPopupWindowAdapter
 * @Description: 污染源PopupWindow列表适配器
 * @date 2016-08-20 上午11:57:36
 */
public class WuRanYuanPopupWindowAdapter extends BaseAdapter {

    private Context context;
    private List<DepartmentChildReturn.DataBean> dataList = new ArrayList<DepartmentChildReturn.DataBean>();

    public WuRanYuanPopupWindowAdapter(Context context, List<DepartmentChildReturn.DataBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int i) {
        return dataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_wuranyuan_popupwindow, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (dataList != null) {
            //是否选中
            if (dataList.get(position).isSelected) {
                holder.tvWuranyuanPopupwindowName.setTextColor(context.getResources().getColor(R.color.common_green));
            } else {
                holder.tvWuranyuanPopupwindowName.setTextColor(context.getResources().getColor(R.color.common_tips));
            }
            //名称
            if (!TextUtils.isEmpty(dataList.get(position).names)) {
                holder.tvWuranyuanPopupwindowName.setText(dataList.get(position).names);
            } else {
                holder.tvWuranyuanPopupwindowName.setText("");
            }

            //跳转基础资料页面
//            convertView.setOnClickListener(new View.OnClickListener() {
//
//                @Override
//                public void onClick(View v) {
//                    Intent i = new Intent(v.getContext(), QiYeZhongXin2Activity.class);
////                    i.putExtra("id", dataList.get(position).id);
//                    v.getContext().startActivity(i);
//                }
//            });
        }
        return convertView;

    }

    /**
     * 自定义接口回调
     */
    private MyClickListener myClickListener;

    public void setMyClickListener(MyClickListener myClickListener) {
        this.myClickListener = myClickListener;
    }

    public interface MyClickListener {
        void onMyClick(int position);
    }

    static class ViewHolder {
        @BindView(R.id.tv_wuranyuan_popupwindow_name)
        TextView tvWuranyuanPopupwindowName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
